import axios from "axios";
import { defineStore } from "pinia";
import  request  from "@/utils/request";
import { BannerItem, GoodItem, ApiRes, HotGoods } from '@/types/data'

export default defineStore('home',{
  state:()=>{
    return{ 
      bannerList:[] as BannerItem[],
      newGoodList: [] as GoodItem[],
      hotGoodList: [] as HotGoods[]
    }
  },
  actions:{
    // 获取轮播图数据
    async getBannerList(){
      const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
      console.log(res.data.result)
      this.bannerList = res.data.result
    },
      // 新鲜好物
      async getNewList() {
        const res = await request.get<ApiRes<GoodItem[]>>('/home/new')
        this.newGoodList = res.data.result
      },
       // 人气推荐
       async getHotList() {
        const res = await request.get<ApiRes<HotGoods[]>>('/home/hot')
        this.hotGoodList = res.data.result
      },
  }
})